"""定义审计相关的常量"""
from typing import Dict, Tuple, NamedTuple


class AuditMeta(NamedTuple):
	action: str
	target_type: str


AUDIT_MAP: Dict[Tuple[str, str], AuditMeta] = {
	("POST", "/system/roles"): AuditMeta("CREATE_ROLE", "ROLE"),
	("PUT", "/system/roles/{role_id}"): AuditMeta("UPDATE_ROLE", "ROLE"),
	("DELETE", "/system/roles/{role_id}"): AuditMeta("DELETE_ROLE", "ROLE"),
	("POST", "/system/permissions"): AuditMeta("CREATE_PERMISSION", "PERMISSION"),
	("PUT", "/system/permissions/{permission_id}"): AuditMeta("UPDATE_PERMISSION", "PERMISSION"),
	("DELETE", "/system/permissions/{permission_id}"): AuditMeta("DELETE_PERMISSION", "PERMISSION"),
	("PUT", "/system/users/{user_id}/enable"): AuditMeta("ENABLE_USER", "USER"),
	("PUT", "/system/users/{user_id}/disable"): AuditMeta("DISABLE_USER", "USER"),
	("POST", "/system/users/{user_code}/roles"): AuditMeta("ASSIGN_ROLE", "USER"),
	("POST", "/system/roles/{role_id}/permissions"): AuditMeta("ASSIGN_PERMISSION", "ROLE"),
	# 设备管理审计日志
	("POST", "/api/v1/devices/stations"): AuditMeta("CREATE_STATION", "STATION"),
	("PUT", "/api/v1/devices/stations/{id}"): AuditMeta("UPDATE_STATION", "STATION"),
	("DELETE", "/api/v1/devices/stations/{id}"): AuditMeta("DELETE_STATION", "STATION"),
	("POST", "/api/v1/devices/boxes"): AuditMeta("CREATE_BOX", "BOX"),
	("PUT", "/api/v1/devices/boxes/{id}"): AuditMeta("UPDATE_BOX", "BOX"),
	("DELETE", "/api/v1/devices/boxes/{id}"): AuditMeta("DELETE_BOX", "BOX"),
	("POST", "/api/v1/devices/rtus"): AuditMeta("CREATE_RTU", "RTU"),
	("PUT", "/api/v1/devices/rtus/{id}"): AuditMeta("UPDATE_RTU", "RTU"),
	("DELETE", "/api/v1/devices/rtus/{id}"): AuditMeta("DELETE_RTU", "RTU"),
	("POST", "/api/v1/devices/meters"): AuditMeta("CREATE_METER", "METER"),
	("PUT", "/api/v1/devices/meters/{id}"): AuditMeta("UPDATE_METER", "METER"),
	("DELETE", "/api/v1/devices/meters/{id}"): AuditMeta("DELETE_METER", "METER"),
	("POST", "/api/v1/devices/stations/{id}/replace"): AuditMeta("REPLACE_STATION", "STATION"),
	("POST", "/api/v1/devices/boxes/{id}/replace"): AuditMeta("REPLACE_BOX", "BOX"),
	("POST", "/api/v1/devices/rtus/{id}/replace"): AuditMeta("REPLACE_RTU", "RTU"),
	("POST", "/api/v1/devices/meters/{id}/replace"): AuditMeta("REPLACE_METER", "METER"),
	("POST", "/api/v1/devices/stations/{id}/decommission"): AuditMeta("DECOMMISSION_STATION", "STATION"),
	("POST", "/api/v1/devices/boxes/{id}/decommission"): AuditMeta("DECOMMISSION_BOX", "BOX"),
	("POST", "/api/v1/devices/rtus/{id}/decommission"): AuditMeta("DECOMMISSION_RTU", "RTU"),
	("POST", "/api/v1/devices/meters/{id}/decommission"): AuditMeta("DECOMMISSION_METER", "METER"),
	# 工单管理审计日志
	("POST", "/api/v1/work-orders"): AuditMeta("CREATE_WORK_ORDER", "WORK_ORDER"),
	("PUT", "/api/v1/work-orders/{work_order_id}"): AuditMeta("UPDATE_WORK_ORDER", "WORK_ORDER"),
	("DELETE", "/api/v1/work-orders/{work_order_id}"): AuditMeta("DELETE_WORK_ORDER", "WORK_ORDER"),
	("PUT", "/api/v1/work-orders/{work_order_id}/dispatch"): AuditMeta("DISPATCH_WORK_ORDER", "WORK_ORDER"),
	("PUT", "/api/v1/work-orders/{work_order_id}/process"): AuditMeta("PROCESS_WORK_ORDER", "WORK_ORDER"),
	("PUT", "/api/v1/work-orders/{work_order_id}/resolve"): AuditMeta("RESOLVE_WORK_ORDER", "WORK_ORDER"),
	("PUT", "/api/v1/work-orders/{work_order_id}/close"): AuditMeta("CLOSE_WORK_ORDER", "WORK_ORDER"),
	# 告警管理审计日志
	("POST", "/api/v1/alarms/batch/ack"): AuditMeta("BATCH_ACK_ALARM", "ALARM"),
	("POST", "/api/v1/alarms/{alarm_id}/ack"): AuditMeta("ACK_ALARM", "ALARM"),
	("PUT", "/api/v1/alarms/{alarm_id}/close"): AuditMeta("CLOSE_ALARM", "ALARM"),
	# 文件管理审计日志
	("POST", "/base/files"): AuditMeta("UPLOAD_FILE", "FILE"),
	("DELETE", "/base/files/{file_id}"): AuditMeta("DELETE_FILE", "FILE"),
	# 区域管理审计日志
	("GET", "/base/regions/provinces"): AuditMeta("GET_PROVINCES", "REGION"),
	("GET", "/base/regions/{provinceCode}/cities"): AuditMeta("GET_CITIES", "REGION"),
	("GET", "/base/regions/{cityCode}/areas"): AuditMeta("GET_AREAS", "REGION"),
	("GET", "/base/regions/trees"): AuditMeta("GET_REGION_TREES", "REGION"),
	("GET", "/base/regions/statistics"): AuditMeta("GET_REGION_STATS", "REGION"),
	# 数据分析审计日志
	("POST", "/api/v1/analytics/consumption"): AuditMeta("CONSUMPTION_STATS", "ANALYTICS"),
	("POST", "/api/v1/analytics/alarms"): AuditMeta("ALARM_STATS", "ANALYTICS"),
	("POST", "/api/v1/analytics/device-inventory"): AuditMeta("DEVICE_INVENTORY_STATS", "ANALYTICS"),
	# 设备事件和操作日志审计日志
	("GET", "/api/v1/device-events/events/{event_id}"): AuditMeta("GET_DEVICE_EVENT", "DEVICE_EVENT"),
	("GET", "/api/v1/device-events/events"): AuditMeta("LIST_DEVICE_EVENTS", "DEVICE_EVENT"),
	("GET", "/api/v1/device-events/logs/{log_id}"): AuditMeta("GET_DEVICE_LOG", "DEVICE_LOG"),
	("GET", "/api/v1/device-events/logs"): AuditMeta("LIST_DEVICE_LOGS", "DEVICE_LOG"),
	# 枚举管理审计日志
	("POST", "/base/enums"): AuditMeta("CREATE_ENUM", "ENUM"),
	("PUT", "/base/enums/{item_id}"): AuditMeta("UPDATE_ENUM", "ENUM"),
	("DELETE", "/base/enums/{item_id}"): AuditMeta("DELETE_ENUM", "ENUM"),
}
